import fetch from '../config/fetch'
import { Toast,Indicator } from 'mint-ui';

export const bhlist = (param) => fetch('/wapsjson/bhlist.json',param);
export const bhskus = (param) => fetch('/wapsjson/bhskus.json',param);
export const hasstock = (param) => fetch('/wapsjson/hasstock.json',param);
export const nostock = (param) => fetch('/wapsjson/nostock.json',param);
export const msgcontent = (param) => fetch('/wapsjson/msgcontent.json',param);
export const skucount = (param) => fetch('/wapsjson/skucount.json',param);
export const allNoStock = (param) => fetch('/wapsjson/allNoStock.json',param);
export const allHasStock = (param) => fetch('/wapsjson/allHasStock.json',param);
export const pideal = (param) => fetch('/wapsjson/pideal.json',param);
export const itemInfo = (param) => fetch('/wapsjson/itemInfo.json',param);
export const getGoodsVipInfo = (param) => fetch('/wapsjson/getGoodsVipInfo.json',param);
export const itemSku = (param) => fetch('/wapsjson/itemSku.json',param);
export const confirmTradeH5 = (param) => fetch('/wapsjson/confirmTradeH5.json',param);
export const tradeOrderDetail = (param) => fetch('/wapsjson/tradeOrderDetail.json',param);
export const getAddressInfo = (param) => fetch('/wapsjson/getAddressInfo.json',param);
export const getH5TradePostFee = (param) => fetch('/wapsjson/getH5TradePostFee.json',param);
export const compeleteH5OrderInfo = (param) => fetch('/wapsjson/compeleteH5OrderInfo.json',param);
export const getWxPayInfo = (param) => fetch('/wapsjson/getWxPayInfo.json',param);
export const getDownloadUrl = (param) => fetch('/wapsjson/getDownloadUrl.json',param);
export const registeCode = (param) => fetch('/wapsjson/registeCode.json',param);
export const submitRegisterInfo = (param) => fetch('/wapsjson/submitRegisterInfo.json',param);
export const ajax = {
    data(){
      return {
        loadingTool:'',
        _imdoing:'',
        myToast:''
      }
    },
    methods: {
        async doajax(method,param,success,err){
          if (this._imdoing==method) {
            return;
          }
          this._imdoing=method;
          this.openLoading();
          this.ajax(await method(param),success,err);
          this.closeLoading();
          this._imdoing='';
        },
        ajax(res, success,err){
            if(res.success){
                success.call(this, res)
            }else{
              if(err!==undefined){
                err.call(this, res);
              } else if (res.auth !== undefined) {
                if (res.authUrl !== undefined) {
                  window.location.href=res.authUrl;//如果有授权地址带回来，跳授权
                }

              } else {
                this.error(res.msg);
              }

            }

        },
      openLoading(){
        Indicator.open();
      },
      closeLoading(){
        Indicator.close();
      },
      success(message){
        if (this.myToast != ''&&this.myToast.visible) {
          this.myToast.close();
        }
        this.myToast=Toast(message);
      },
      error(message){
        if (this.myToast != ''&&this.myToast.visible) {
          this.myToast.close();
        }
        this.myToast=Toast(message);
      },
      warn(message){
        if (this.myToast != ''&&this.myToast.visible) {
          this.myToast.close();
        }
        this.myToast=Toast(message);
      }
    }
}
